﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Moqikaka.Util
{
    /// <summary>
    /// json 帮助类
    /// </summary>
    public class JosnHelper
    {
        /// <summary>
        /// 反序列化Json数据为指定对象
        /// </summary>
        /// <typeparam name="T">指定返回对象</typeparam>
        /// <param name="str">Json字符串</param>
        /// <returns>反序列化后的T对象</returns>
        public static T Deserialize<T>(string str)
        {
            return JsonConvert.DeserializeObject<T>(str);
        }

        /// <summary>
        /// 序列化对象为Json数据
        /// </summary>
        /// <param name="obj">序列对象</param>
        /// <returns>序列化后的字符串</returns>
        public static string Serialize(object obj)
        {
            return JsonConvert.SerializeObject(obj);
        }


    }
}
